<?php
/**
 * Description:
 * Author: hezhizheng
 * Date: 2018/11/14
 * Time: 14:41
 * Created by Created by Panxsoft.
 */

namespace App\Models\Customers;

use App\Models\Setting;
use App\Models\Store\Store;
use Illuminate\Database\Eloquent\Model;

class CustomerGroup extends Model
{
    const CUSTOMER_GROUP_ID_DEFAULT = 1; // 普通/默认客户

    protected $guarded = [];

    protected $table = 'customer_group';

    protected $primaryKey = 'customer_group_id';

    public $timestamps = false;

    /**
     * @param $store_id
     * @return int|mixed
     */
    public static function getConfigCustomerGroupId(int $store_id): int
    {
        $settings = Setting::findConfigByCode(Setting::CODE_CONFIG, $store_id);

        if (isset($settings['config_customer_group_id'])) {
            return (int) $settings['config_customer_group_id'];
        } else {
            throw new \LogicException("Store [$store_id] config customer group id missing");
        }
    }
}